package com.sq.partner.manager.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.ReportDao;
import com.sq.partner.manager.service.ReportService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.excel.ExcelEntity;
import com.sq.partner.manager.util.excel.ExportExcelBuilderTool;

@Service
public class ReportServiceImpl implements ReportService{
    
    @Resource
    private ReportDao reportDao;
    @Resource
    ExportExcelBuilderTool exportExcelBuilderTool;
    
    /**
     * 按合作伙伴查询近十二个月有效保单数量
     */
    @Override
    public Page<Map<String,Object>> queryPolicyAmount(Page<Map<String, Object>> page) throws Exception {
        return reportDao.queryPolicyAmount(page);
    }
    /**
     * 查询所有的合作伙伴
     */
    @Override
    public List<Map<String,Object>> queryAllPartner(Map<String,Object> paramMap) throws Exception {
        return reportDao.queryAllPartner(paramMap);
    }
    /**
     * 查询所有的机构
     */
    @Override
    public List<Map<String,Object>> queryAllDept(Map<String,Object> paramMap) throws Exception {
        return reportDao.queryAllDept(paramMap);
    }
    
    /**
     * 根据合作伙伴按机构查询单量
     */
    @Override
    public List<Map<String,Object>> queryPartner(Map<String,Object> paramMap) throws Exception {
        return reportDao.queryPartner(paramMap);
    }
    /**
     * 按合作伙伴下查询
     */
    @Override
    public List<Map<String,Object>> querypartnerAmount(Map<String,Object> paramMap) throws Exception {
        return reportDao.querypartnerAmount(paramMap);
    }
    /**
     * 按合作伙伴下查询机构数据
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String,Object>> queryDeptPartner(Map<String,Object> paramMap) throws Exception {
        return reportDao.queryDeptPartner(paramMap);
    }
    
    /**
     * 查询合作伙伴的投入成本
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String,Object>> queryChannelCost(Map<String,Object> paramMap) throws Exception {
        return reportDao.queryChannelCost(paramMap);
    }
    
    /**
     * 下载Excel
     */
    @Override
    public void downloadFile(List<Map<String, Object>> list,HttpServletResponse response, String months)
            throws Exception {
        ExcelEntity excel = new ExcelEntity();
        excel.setResults(list);
        excel.setFileName("report");
        excel.setTitles("合作伙伴名称,合作伙伴代码," + months + ",近12个月总保费,近12个月总单量,总保费,今年总单量,今年总保费,总单量,投入成本");
        excel.setTitleKeys("CHANNEL_NAME,PARTNER_CODE,PREMIUM0,PREMIUM1,PREMIUM2,PREMIUM3,PREMIUM4,PREMIUM5,PREMIUM6,PREMIUM7,PREMIUM8,PREMIUM9,PREMIUM10,PREMIUM11,COUNT0,COUNT1,COUNT2,COUNT3,COUNT4,COUNT5,COUNT6,COUNT7,COUNT8,COUNT9,COUNT10,COUNT11,PREMIUM,POL_NUM,ALLPREMIUM,ANNUAL_TOTAL_POL,ANNUAL_TOTAL_PREMIUM,ALLCOUNT,CHANNEL_COST");
        excel.setColumns("30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30，30,30");
        exportExcelBuilderTool.buildExcel(response,excel);    
    }
    
    /**
     * 查询下载Excel数据
     */
    @Override
    public List<Map<String,Object>> queryReportFileData(Map<String,Object> paramMap) throws Exception {
        return reportDao.queryReportFileData(paramMap);
    }
    
    /**
     * 查询合作伙伴名称和代码 lfd added 20190909
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public Page<Map<String,Object>> queryPartnerInfo(Page<Map<String, Object>> page) throws Exception {
        return reportDao.queryPartnerInfo(page);
    }
}
